const root = [
    {
        id: 1,
        name: '1x',
        children: [
            {
                id: 11, name: '11x', children: [{ id: 111, name: '111x' }]
            },
            { id: 12, name: '12x' },
        ]
    },
    {
        id: 2,
        name: '1x',
        children: [
            {
                id: 21, name: '21x', children: [{ id: 211, name: '21x' }]
            },
            { id: 12, name: '12x' },
        ]
    },
    { id: 3, name: '3x' }
]
//输出以下格式，
//{id:1,name:'1x',children:[11,21]}
//{id:11,name:'1x',parent:[1],children:[111]}
//{id:12,name:'12x',parent:[1]}
//{id:3,name:'3x'}

function dataDispose(root) {
    let arr = []
    function dataTransform(data, parentId) {
        data.forEach(item => {
            let obj = { id: item.id, name: item.name }
            if (parentId) {
                obj.parent = [parentId]
            }
            arr.push(obj)
            if (item.children) {
                obj.children = []
                for (let item1 of item.children) {
                    obj.children.push(item1.id)
                }
                dataTransform(item.children, item.id)
            }
        })
    }
    dataTransform(root, 0)
    return arr
}


console.log(arr);